TABLES
T_VALUES	LIKE	TVARVC

EXCEPTIONS
UNABLE_TO_CREATE	Unable to create
UNABLE_TO_UPDATE	Unable to update record
NAME_EMPTY	Field name is empty
COMMIT_FAILED	The commit has failed

CODE
FUNCTION zwrite_tvarv.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  TABLES
*"      T_VALUES STRUCTURE  TVARVC
*"  EXCEPTIONS
*"      UNABLE_TO_CREATE
*"      UNABLE_TO_UPDATE
*"      NAME_EMPTY
*"      COMMIT_FAILED
*"----------------------------------------------------------------------
  TABLES: tvarvc.

  LOOP AT t_values.

    IF t_values-name IS INITIAL.
      RAISE name_empty.
      EXIT.
    ENDIF.

    SELECT SINGLE * FROM tvarvc
      INTO CORRESPONDING FIELDS OF tvarvc
     WHERE name = t_values-name AND
           type = t_values-type AND
           numb = t_values-numb.

    IF sy-subrc = 0.
      MOVE-CORRESPONDING t_values TO tvarvc.
      UPDATE tvarvc.
      IF sy-subrc = 0.
        COMMIT WORK.
        if sy-subrc <> 0.
          raise commit_failed.
          exit.
        endif.
      ELSE.
        RAISE unable_to_update.
      ENDIF.
    ELSE.
      INSERT INTO tvarvc VALUES t_values.
      IF sy-subrc = 0.
        COMMIT WORK.
        if sy-subrc <> 0.
          raise commit_failed.
          exit.
        endif.
      ELSE.
        RAISE unable_to_create.
      ENDIF.
    ENDIF.

  ENDLOOP.



ENDFUNCTION.